package edu.dublbo.app.habitplusfavorite.controller;

import edu.dublbo.app.habitplusfavorite.service.IVisitorLastHistoryService;
import edu.dublbo.app.habitplusfavorite.vo.VisitDataVo;
import edu.dublbo.commons.lang.Result;
import edu.dublbo.commons.util.IpUtil;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.servlet.http.HttpServletRequest;

/**
 * <p>
 * 访客的最近一次访问的历史 前端控制器
 * </p>
 *
 * @author habitplus
 * @since 2021-11-30
 */
@RestController
@RequestMapping("/page-visitor")
public class VisitorLastHistoryController {
    @Autowired
    private IVisitorLastHistoryService service;

    @GetMapping(value = "/statics")
    public Result statics(HttpServletRequest request) {
        int port = request.getLocalPort();
        String url = IpUtil.getSelfIpAddress() + ":" + port + "/habitplus-favorite";
        VisitDataVo vd = service.statics(url);
        return Result.success(vd);
    }
}
